﻿using ManagementApi.Models.Project;
using Modules;
using Modules.Project;
using PmSoft;
using PmSoft.ApplicationContext;
using System.ComponentModel.DataAnnotations;

namespace ManagementApi.Models.Commander
{
    public class CommanderProjectEditForm
    {
        ///// <summary>
        ///// 指挥部Id
        ///// </summary>
        //[Display(Name = "指挥部Id")]
        //[Required(ErrorMessage = "{0}不能为空")]
        //public int? CommanderId { get; set; }

        /// <summary>
        /// 项目Id
        /// </summary>
        [Display(Name = "项目Id")]
        [Required(ErrorMessage = "{0}不能为空")]
        public int ProjectId { get; set; }

        /// <summary>
        /// 项目名称
        /// </summary>
        [Display(Name = "项目名称")]
        public string? ProjectName { get; set; }
    }

    public static partial class CommanderProjectExceptions
    {
        public static IEnumerable<CommanderProjectEditForm> AsForm(this IEnumerable<CommanderProject> entity, IApplicationContext applicationContext)
        {
            List<CommanderProjectEditForm> result = new List<CommanderProjectEditForm>();
            foreach (var item in entity)
            {
                CommanderProjectEditForm commanderProjectEditForm = new CommanderProjectEditForm()
                {
                    ProjectId = item.ProjectId
                };
                commanderProjectEditForm.ProjectName = applicationContext.GetService<ProjectService>().GetProjectInfo(item.ProjectId)?.Name;
                result.Add(commanderProjectEditForm);
            }
            return result;
        }
    }
}
